<template>
    <div class="data_list">

      <div v-if="tableData.list.length>0" class="item">
        <img :src="tableData.list[0].header" class="img"/>
        <div class="info">
          <div class="name">{{tableData.list[0].userName}}</div>
          <div class="student">{{tableData.list[0].company}}</div>
        </div>
      </div>

        <div class="item" v-for="item in tableData.list" >
            <div class="info">
              <div class="name">{{item.matchName}} {{item.matchNameExt?'（'+item.matchNameExt+'）': ''}}</div>
              <div class="attr" style="display: block;">赛项：{{item.itemName}}（{{item.groupName}}）</div>
              <div class="attr">层级：{{item.matchLevel ==1 ? '国赛': '省赛'}}</div>
              <div class="attr">单位：{{item.company}}</div>
              <div class="attr">指导老师：{{item.teacher}}</div>
              <div class="attr">证书编号：{{item.certificate}}</div>
              <div class="attr" style="display: block;" v-if="item.url"><span @click="viewUrl(item.url)">查看证书</span></div>
              </div>
            <div class="jiang">{{item.score}}</div>
        </div>

        <!--
        <div class="item"  @click="handleaCertificate">
            <img class="img" src="https://img1.baidu.com/it/u=1649332224,709616198&fm=253&fmt=auto&app=120&f=JPEG?w=607&h=405" />
            <div class="info">
                 <div class="name">山东省潍坊地区选拔赛</div>
                 <div class="student">虚拟篮球雪橇 <span>李依依</span></div>
                 <div class="attr">编号：RET2023020189</div>
                 <div class="attr">赛项：儿童足球 <span>查看证书</span></div>
            </div>
            <div class="jiang">二等奖</div>
        </div>

        <div class="item"  @click="handleaCertificate">
            <img class="img" src="https://img2.baidu.com/it/u=1702929222,2800233690&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=753" />
            <div class="info">
                 <div class="name">山东省潍坊地区选拔赛</div>
                 <div class="student">潍坊市第一中学 <span>李依依</span></div>
                 <div class="attr">编号：RET2023020189</div>
                 <div class="attr">赛项：空中格斗赛 <span>查看证书</span></div>
            </div>
            <div class="jiang">三等奖</div>
        </div>
        -->

    </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import {useRoute} from "vue-router";
import baseService from "@/service/baseService";
import {ElMessage} from "element-plus";
import app from "@/constants/app";
import {getCache} from "@/utils/cache";
import router from "@/router";
const route = useRoute();

const tableData = reactive({
  list: []
});

const showViewUrlFlag = ref(false);

const certificateJson = getCache('certificate', { isSessionStorage: true }, {});
debugger

const realName = route.query.realName ? route.query.realName : certificateJson.realName;
const certificate = route.query.certificate ? route.query.certificate : certificateJson.certificate;
const idCard = certificateJson.idCard ? certificateJson.idCard : route.query.idCard;

console.log(realName);


//查看证书
const viewUrl = (url: string) => {
  window.open(url);
};

// 查询证书
const queryCertificateBy = () => {
  baseService
      .post("/front/spuser/queryCertificateBy", {realName, idCard, certificate})
      .then((res) => {
            if (res.code === 0) {
              tableData.list = res.data;
            } else {
              ElMessage.error(res.msg);
            }
          }
      );
};

const downLoadFile = (url: string, name: string) => {
  let a = document.createElement('a');
  let evt = document.createEvent('MouseEvents');
  a.download = '晋级列表';
  a.href = app.api+"/front/download?imageUrl="+ url +"&fileName=" + name;
  evt.initEvent('click',true,true);
  a.dispatchEvent(evt);
  window.URL.revokeObjectURL(a.href);
}

const back =() => {
  router.push("/certificate");
}

queryCertificateBy();




</script>

<style lang="scss" scoped>
@import "./zstyle.scss";
</style>
